<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class News extends CI_Controller {

        private $data = array();
        private $syslang;
        private $fields = array('post_title','content');

        public function __construct(){

            parent::__construct();

            $this->data['url'] = base_url();
            $this->syslang = $this->lang->lang();
            $this->data['local_lang'] = $this->syslang;

            $this->load->helper('language');
            $this->load->config('pages');
            // load language file
            $this->lang->load('it-montenengro');

            /* Translate Class */
            $this->load->library('translate',array('lang'=>$this->lang->lang()));

            //urlify library for prety url
            $linktoclass = "urlify.php";
            require_once($linktoclass);

        }

        public function index()
        { 
            show_404();
        }

        public function get_news($news_title){

            $my_arr = explode('-',$news_title);
            $id = $my_arr[count($my_arr)-1];
            unset($my_arr[count($my_arr)-1]);
            
            $this->data['title'] = implode('-',$my_arr);
            $this->data['page'] = 'news';

            $q="
            SELECT posts.*, gallery.path as path_gallery, gallery.ID as ID_gallery
            FROM posts
            LEFT JOIN gallery ON gallery.posts_ID = posts.ID
            WHERE posts.ID = $id
            ";

            $this->data['news'] = $this->db->query($q)->row_array();

            // Translate
            $this->data['news'] = $this->translate->trans_row_array($this->data['news']);

            $this->db->order_by('order asc, ID asc');
            $this->data['pictures'] = $this->db->get_where('pictures', array('gallery_ID'=>$this->data['news']['ID_gallery']))->result_array();

            //echo 'GALLERY ID:'.$this->data['platform']['ID_gallery']."<br /><br />";
            //print_r($this->data['pictures']);
            $this->data['tickerNews'] = $this->translate->trans_res_array($this->db->get_where('posts',array('post_type'=>'news'))->result_array());

            $this->template->build('news/index', $this->data);

        }

    }

    /* End of file news.php */
    /* Location: ./application/controllers/news.php */